﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CNVP.Framework.Utils;
using CNVP.Framework;
using CNVP.JShop.UI;
using CNVP.Framework.Helper;

namespace CNVP.JShop.Web.Member
{
    public partial class GetAddressList : UserPage
    {
        BLL.CNVP_GetAddress bll = new BLL.CNVP_GetAddress();
        public int rplistCount = 0;
        public int PageIndex = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && Public.IsNumber(Request.QueryString["Page"]))
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            if (!IsPostBack)
            {
                StartLoad(PageIndex);
                btDelete.Attributes.Add("onclick", "if(ifCheck()){return confirm('确定删除该记录吗?');}else{alert('请选择记录！');return false;};");
            }
        }

        /// <summary>
        /// PageNavigator1_PageChange 的摘要说明
        /// 分页加载列表函数
        /// </summary>
        protected void StartLoad(int PageIndex)
        {
            int i, j;
            DataTable dt = null;
            int pageNum = 20;
            SQLConditionInfo[] st = new SQLConditionInfo[1];
            st[0] = new SQLConditionInfo("@membername", CookieUserID);
            dt = bll.GetPage(this.GetType().Name, PageIndex, pageNum, out i, out j, st);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    rplistCount = dt.Rows.Count;//行数
                    //----------------------------------------添加列------------------------------------------------
                    dt.Columns.Add("oID", typeof(string));
                    dt.Columns.Add("oTrueName", typeof(string));
                    dt.Columns.Add("oProvinceCityArea", typeof(string));
                    dt.Columns.Add("oGetAddress", typeof(string));
                    dt.Columns.Add("oZipCode", typeof(string));
                    dt.Columns.Add("oMobilePhone", typeof(string));
                    dt.Columns.Add("oPhone", typeof(string));
                    dt.Columns.Add("oIsTolerant", typeof(string));
                    //----------------------------------------添加列结束--------------------------------------------

                    for (int k = 0; dt.Rows.Count > k; k++)
                    {
                        dt.Rows[k]["oID"] = dt.Rows[k]["ID"].ToString();
                        dt.Rows[k]["oTrueName"] = dt.Rows[k]["TrueName"].ToString();
                        string PostAddress_Str = new BLL.CNVP_Province().GetSingle_CNVP_ProvinceByCode(dt.Rows[k]["Province"].ToString()).Name + new BLL.CNVP_City().GetSingle_CNVP_CityByCode(dt.Rows[k]["City"].ToString()).Name + new BLL.CNVP_Area().GetSingle_CNVP_AreaByCode(dt.Rows[k]["Area"].ToString()).Name;
                        dt.Rows[k]["oProvinceCityArea"] = PostAddress_Str;
                        dt.Rows[k]["oGetAddress"] = dt.Rows[k]["GetAddress"].ToString();
                        dt.Rows[k]["oZipCode"] = dt.Rows[k]["ZipCode"].ToString();
                        dt.Rows[k]["oMobilePhone"] = dt.Rows[k]["MobilePhone"].ToString();
                        dt.Rows[k]["oPhone"] = dt.Rows[k]["Phone"].ToString();
                        if (dt.Rows[k]["IsTolerant"].ToString() == "1")
                        {
                            dt.Rows[k]["oIsTolerant"] = "<font color=\"red\">是</font>";
                        }
                        else
                        {
                            dt.Rows[k]["oIsTolerant"] = "否";
                        }

                    }
                }
            }
            rpList.DataSource = dt;
            rpList.DataBind();
            paging.InnerHtml = Paginator.Pagination(PageIndex, i, j);
        }

        protected void btDelete_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.rpList.Items.Count; i++)
            {
                CheckBox cbCheck = (CheckBox)this.rpList.Items[i].FindControl("cbCheck");
                if (cbCheck.Checked == true)
                {

                    bll.Delete_CNVP_GetAddress(int.Parse(cbCheck.ToolTip));
                }
            }
            StartLoad(PageIndex);
        }

        protected void btAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("GetAddressEdit.aspx");
        }
    }
}
